package br.com.qualityempresa.core

import br.com.qualityempresa.seguranca.AutenticacaoUtils
import br.com.qualityempresa.seguranca.AutorizacaoUtils

class MenuTagLib {
	
	def menuPrincipal = { attrs, body ->
		def controle = params.controller
		def opcoes = [
		]
		
		for (int i = 0; i < opcoes.size; i++) {
			def opcao = opcoes[i]
			if (opcao.controller.equals(controle)) {
				out << """<li class="active">"""
			} else {
				out << """<li>"""
			}
			out << """   <a href="${createLink(controller:"$opcao.controller",action:"$opcao.action")}">"""
			out << """      <i class="$opcao.icon"></i> """ + message(code:opcao.title)
			out << """   </a>"""
			out << """</li>"""
		}
		out << body()
	}

	def menuUsuario = {attrs, body ->
		def autenticacaoUtils = new AutenticacaoUtils()
		def autorizacaoUtils = new AutorizacaoUtils()
		out << """   <li class="dropdown">"""
		out << """      <a href="#" class="dropdown-toggle" data-toggle="dropdown"> """ 		
		out << """      <i class="icon-size24-user"></i> """ + autenticacaoUtils.getUsuarioAutenticado().nome
		out << """         <b class="caret"></b>"""
		out << """      </a>"""
		out << """      <ul class="dropdown-menu">"""
		out << """         <li>"""
		out << """            <a href="${createLink(controller:"usuario",action:"perfil")}">"""
		out << """               <i class="icon-edit"></i> Perfil """
		out << """            </a>"""
		out << """         </li>"""
		if (autorizacaoUtils.verificarPermissao("usuario", "list")) {
			out << """         <li class="divider"></li>"""
			out << """         <li>"""
			out << """            <a href="${createLink(controller:"usuario",action:"list")}">"""
			out << """               <i class="icon-list-alt"></i> Usuarios do Sistema """
			out << """            </a>"""
			out << """         </li>"""
		}
		if (autorizacaoUtils.verificarPermissao("perfil", "list")) {
			out << """         <li>"""
			out << """            <a href="${createLink(controller:"perfil",action:"list")}">"""
			out << """               <i class="icon-list-alt"></i> Perfis de Usuário"""
			out << """            </a>"""
			out << """         </li>"""
		}
		if (autorizacaoUtils.verificarPermissao("acesso", "list")) {
			out << """         <li>"""
			out << """            <a href="${createLink(controller:"acesso",action:"list")}">"""
			out << """               <i class="icon-list-alt"></i> Acessos de Sistema"""
			out << """            </a>"""
			out << """         </li>"""
		}
		if (autorizacaoUtils.verificarPermissao("acesso", "list")) {
			out << """         <li>"""
			out << """            <a href="${createLink(controller:"horarioAcesso",action:"list")}">"""
			out << """               <i class="icon-list-alt"></i>  Horário de Acesso"""
			out << """            </a>"""
			out << """         </li>"""
		}
		
		
		out << """         <li class="divider"></li>"""
		out << """         <li>"""
		out << """            <a href="${createLink(controller:"painel",action:"sair")}">"""
		out << """               Sair """
		out << """            </a>"""
		out << """         </li>"""
		out << """      </ul>"""
		out << """   </li>"""
		out << body()
	}
	
	def menuCadastros = {attrs, body ->
		def autenticacaoUtils = new AutenticacaoUtils()
		def autorizacaoUtils = new AutorizacaoUtils()
		out << """   <li class="dropdown">"""
		out << """      <a href="#" class="dropdown-toggle" data-toggle="dropdown">Cadastros """
		out << """         <b class="caret"></b>"""
		out << """      </a>"""
		out << """      <ul class="dropdown-menu">"""
		if (autorizacaoUtils.verificarPermissao("area", "list")) {
			out << """         <li class="divider"></li>"""
			out << """         <li>"""
			out << """            <a href="${createLink(controller:"area",action:"list")}">"""
			out << """               <i class="icon-list-alt"></i> Areas """
			out << """            </a>"""
			out << """         </li>"""
		}
		if (autorizacaoUtils.verificarPermissao("nivelHierarquico", "list")) {
			out << """         <li class="divider"></li>"""
			out << """         <li>"""
			out << """            <a href="${createLink(controller:"nivelHierarquico",action:"list")}">"""
			out << """               <i class="icon-list-alt"></i> Nivel Hierarquico """
			out << """            </a>"""
			out << """         </li>"""
		}
		if (autorizacaoUtils.verificarPermissao("cargo", "list")) {
			out << """         <li class="divider"></li>"""
			out << """         <li>"""
			out << """            <a href="${createLink(controller:"cargo",action:"list")}">"""
			out << """               <i class="icon-list-alt"></i> Cargos """
			out << """            </a>"""
			out << """         </li>"""
		}
		if (autorizacaoUtils.verificarPermissao("funcao", "list")) {
			out << """         <li class="divider"></li>"""
			out << """         <li>"""
			out << """            <a href="${createLink(controller:"funcao",action:"list")}">"""
			out << """               <i class="icon-list-alt"></i> Funcoes """
			out << """            </a>"""
			out << """         </li>"""
		}
		out << """         <li class="divider"></li>"""
		out << """      </ul>"""
		out << """   </li>"""
		out << body()
	}
	
	def menuAdministracao = {attrs, body ->
		def autenticacaoUtils = new AutenticacaoUtils()
		def autorizacaoUtils = new AutorizacaoUtils()
		out << """   <li class="dropdown">"""
		out << """      <a href="#" class="dropdown-toggle" data-toggle="dropdown">"""		
		out << """      <i class="icon-size24-admin"></i> """ 
		out << """         Administracao """
		out << """         <b class="caret"></b>"""
		out << """      </a>"""
		out << """      <ul class="dropdown-menu">"""
		if (autorizacaoUtils.verificarPermissao("organizacao", "list")) {
			out << """         <li class="divider"></li>"""
			out << """         <li>"""
			out << """            <a href="${createLink(controller:"organizacao",action:"list")}">"""
			out << """               <i class="icon-list-alt"></i> Organizacao """
			out << """            </a>"""
			out << """         </li>"""
		}
		if (autorizacaoUtils.verificarPermissao("organograma", "list")) {
			out << """         <li class="divider"></li>"""
			out << """         <li>"""
			out << """            <a href="${createLink(controller:"organograma",action:"list")}">"""
			out << """               <i class="icon-list-alt"></i> Organograma """
			out << """            </a>"""
			out << """         </li>"""
		}
		if (autorizacaoUtils.verificarPermissao("area", "list")) {
			out << """         <li class="divider"></li>"""
			out << """         <li>"""
			out << """            <a href="${createLink(controller:"area",action:"list")}">"""
			out << """               <i class="icon-list-alt"></i> Areas """
			out << """            </a>"""
			out << """         </li>"""
		}
		if (autorizacaoUtils.verificarPermissao("nivelHierarquico", "list")) {
			out << """         <li class="divider"></li>"""
			out << """         <li>"""
			out << """            <a href="${createLink(controller:"nivelHierarquico",action:"list")}">"""
			out << """               <i class="icon-list-alt"></i> Nivel Hierarquico """
			out << """            </a>"""
			out << """         </li>"""
		}
		if (autorizacaoUtils.verificarPermissao("cargo", "list")) {
			out << """         <li class="divider"></li>"""
			out << """         <li>"""
			out << """            <a href="${createLink(controller:"cargo",action:"list")}">"""
			out << """               <i class="icon-list-alt"></i> Cargos """
			out << """            </a>"""
			out << """         </li>"""
		}
		if (autorizacaoUtils.verificarPermissao("funcao", "list")) {
			out << """         <li class="divider"></li>"""
			out << """         <li>"""
			out << """            <a href="${createLink(controller:"funcao",action:"list")}">"""
			out << """               <i class="icon-list-alt"></i> Funcoes """
			out << """            </a>"""
			out << """         </li>"""
		}
		if (autorizacaoUtils.verificarPermissao("complexidadeCargo", "list")) {
			out << """         <li class="divider"></li>"""
			out << """         <li>"""
			out << """            <a href="${createLink(controller:"complexidadeCargo",action:"list")}">"""
			out << """               <i class="icon-list-alt"></i> Complexidade do Cargo """
			out << """            </a>"""
			out << """         </li>"""
		}
		if (autorizacaoUtils.verificarPermissao("colaborador", "list")) {
			out << """         <li class="divider"></li>"""
			out << """         <li>"""
			out << """            <a href="${createLink(controller:"colaborador",action:"list")}">"""
			out << """               <i class="icon-list-alt"></i> Colaborador """
			out << """            </a>"""
			out << """         </li>"""
		}
		out << """         <li class="divider"></li>"""
		out << """      </ul>"""
		out << """   </li>"""
		out << body()
	}

	def menuGestao = {attrs, body ->
		def autenticacaoUtils = new AutenticacaoUtils()
		def autorizacaoUtils = new AutorizacaoUtils()
		out << """   <li class="dropdown">"""
		out << """      <a href="#" class="dropdown-toggle" data-toggle="dropdown">"""		
		out << """      <i class="icon-size24-group"></i> """ 
		out << """         Gestao """
		out << """         <b class="caret"></b>"""
		out << """      </a>"""
		out << """      <ul class="dropdown-menu">"""
		if (autorizacaoUtils.verificarPermissao("gestao", "list")) {
			out << """         <li class="divider"></li>"""
			out << """         <li>"""
			out << """            <a href="${createLink(controller:"gestao",action:"list")}">"""
			out << """               <i class="icon-list-alt"></i> Gestao """
			out << """            </a>"""
			out << """         </li>"""
		}
		if (autorizacaoUtils.verificarPermissao("grupoDesempenho", "list")) {
			out << """         <li class="divider"></li>"""
			out << """         <li>"""
			out << """            <a href="${createLink(controller:"grupoDesempenho",action:"list")}">"""
			out << """               <i class="icon-list-alt"></i> Grupo de Desempenho"""
			out << """            </a>"""
			out << """         </li>"""
		}
		if (autorizacaoUtils.verificarPermissao("gruposGestao", "list")) {
			out << """         <li class="divider"></li>"""
			out << """         <li>"""
			out << """            <a href="${createLink(controller:"gruposGestao",action:"list")}">"""
			out << """               <i class="icon-list-alt"></i> Parametrizar Grupos"""
			out << """            </a>"""
			out << """         </li>"""
		}
		if (autorizacaoUtils.verificarPermissao("competencia", "list")) {
			out << """         <li class="divider"></li>"""
			out << """         <li>"""
			out << """            <a href="${createLink(controller:"competencia",action:"list")}">"""
			out << """               <i class="icon-list-alt"></i> Competencia """
			out << """            </a>"""
			out << """         </li>"""
		}		
		if (autorizacaoUtils.verificarPermissao("perfilCompetencia", "list")) {
			out << """         <li class="divider"></li>"""
			out << """         <li>"""
			out << """            <a href="${createLink(controller:"perfilCompetencia",action:"list")}">"""
			out << """               <i class="icon-list-alt"></i> Perfil da Competencia """
			out << """            </a>"""
			out << """         </li>"""
		}
		if (autorizacaoUtils.verificarPermissao("contrato", "list")) {
			out << """         <li class="divider"></li>"""
			out << """         <li>"""
			out << """            <a href="${createLink(controller:"contrato",action:"list")}">"""
			out << """               <i class="icon-list-alt"></i> Contrato """
			out << """            </a>"""
			out << """         </li>"""
		}
		if (autorizacaoUtils.verificarPermissao("competencia", "definir")) {
			out << """         <li class="divider"></li>"""
			out << """         <li>"""
			out << """            <a href="${createLink(controller:"competencia",action:"list")}">"""
			out << """               <i class="icon-list-alt"></i> Definir Competencia"""
			out << """            </a>"""
			out << """         </li>"""
		}
		if (autorizacaoUtils.verificarPermissao("indicador", "list")) {
			out << """         <li class="divider"></li>"""
			out << """         <li>"""
			out << """            <a href="${createLink(controller:"indicador",action:"list")}">"""
			out << """               <i class="icon-list-alt"></i> Indicador de Compentecia"""
			out << """            </a>"""
			out << """         </li>"""
		}
		if (autorizacaoUtils.verificarPermissao("indicadorResultado", "list")) {
			out << """         <li class="divider"></li>"""
			out << """         <li>"""
			out << """            <a href="${createLink(controller:"indicadorResultado",action:"list")}">"""
			out << """               <i class="icon-list-alt"></i> Indicador de Resultado"""
			out << """            </a>"""
			out << """         </li>"""
		}
		out << """         <li class="divider"></li>"""
		out << """      </ul>"""
		out << """   </li>"""
		out << body()
	}

	def menuAvaliacao = {attrs, body ->
		def autenticacaoUtils = new AutenticacaoUtils()
		def autorizacaoUtils = new AutorizacaoUtils()
		out << """   <li class="dropdown">"""
		out << """      <a href="#" class="dropdown-toggle" data-toggle="dropdown">"""		
		out << """      <i class="icon-size24-avaliacao"></i> """ 
		out << """         Avaliacao """
		out << """         <b class="caret"></b>"""
		out << """      </a>"""
		out << """      <ul class="dropdown-menu">"""
		if (autorizacaoUtils.verificarPermissao("avaliacao", "list")) {
			out << """         <li class="divider"></li>"""
			out << """         <li>"""
			out << """            <a href="${createLink(controller:"avaliacao",action:"list")}">"""
			out << """               <i class="icon-list-alt"></i> Avaliacao """
			out << """            </a>"""
			out << """         </li>"""
		}
		if (autorizacaoUtils.verificarPermissao("observacao", "list")) {
			out << """         <li class="divider"></li>"""
			out << """         <li>"""
			out << """            <a href="${createLink(controller:"observacao",action:"list")}">"""
			out << """               <i class="icon-list-alt"></i> Observacao """
			out << """            </a>"""
			out << """         </li>"""
		}
		out << """         <li class="divider"></li>"""
		out << """      </ul>"""
		out << """   </li>"""
		out << body()
	}

	def menuResultados = {attrs, body ->
		def autenticacaoUtils = new AutenticacaoUtils()
		def autorizacaoUtils = new AutorizacaoUtils()
		out << """   <li class="dropdown">"""
		out << """      <a href="#" class="dropdown-toggle" data-toggle="dropdown">"""		
		out << """      <i class="icon-size24-stats"></i> """
		out << """         Resultados """
		out << """         <b class="caret"></b>"""
		out << """      </a>"""
		out << """      <ul class="dropdown-menu">"""
		
		out << """         <li class="divider"></li>"""
		out << """      </ul>"""
		out << """   </li>"""
		out << body()
	}
}
